package com.yunshangwoniu.core.page;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.util.Assert;

/**
 * 分页对象
 * @author 云上蜗牛
 * @param <T>
 */
public class Page<T> implements Serializable
{
	private static final long serialVersionUID = 2969095863736103333L;
	private long allCount;						//最大记录数
	private long currentPageNum;				//当前页
	private long allPageNum;					//共有多少页
	private long countOfPerPage;				//每页多少条记录
	private long beginRecordNum;				//开始的记录数
	private long endRecordNum;					//结束的记录数
	private List<T> records;					//分页数据
	private Map<String,Object> params;			//查询条件
	private String pageCententHTML;				//分页的html代码 由pageService生成
	private String url = "";
	
	
	public Page(long currentPageNum,long countOfPerPage,String url)
	{
		this.currentPageNum = currentPageNum;
		this.countOfPerPage = countOfPerPage;
		this.url = url;
		beginRecordNum = currentPageNum>1?countOfPerPage*(currentPageNum-1):0;
		endRecordNum = currentPageNum>1?beginRecordNum + countOfPerPage-1:countOfPerPage;
		if(currentPageNum<=0)
		{
			endRecordNum = 0;
			beginRecordNum = 0;
		}
	}
	
	public void pageBuilder(long allCount,List<T> list)
	{
		setAllCount(allCount);
		this.records = list;
		Assert.isTrue(currentPageNum!=0&&countOfPerPage!=0, "countOfPerPage OR currentPageNum 输入不合法!");
		allPageNum = allCount<countOfPerPage&&allCount!=0?1:allCount==0?0:allCount%countOfPerPage==0?allCount/countOfPerPage:(allCount/countOfPerPage)+1;
	}
	
	
	public long getAllCount()
	{
		return allCount;
	}
	private void setAllCount(long allCount)
	{
		this.allCount = allCount;
		
	}
	public long getCurrentPageNum()
	{
		return currentPageNum;
	}
	public void setCurrentPageNum(long currentPageNum)
	{
		this.currentPageNum = currentPageNum;
	}
	public long getAllPageNum()
	{
		return allPageNum;
	}
	public void setAllPageNum(long allPageNum)
	{
		this.allPageNum = allPageNum;
	}
	public long getCountOfPerPage()
	{
		return countOfPerPage;
	}
	public void setCountOfPerPage(long countOfPerPage)
	{
		this.countOfPerPage = countOfPerPage;
	}

	public List<T> getRecords()
	{
		return records;
	}
	public void setRecords(List<T> records)
	{
		this.records = records;
	}

	public long getBeginRecordNum()
	{
		return beginRecordNum;
	}

	public void setBeginRecordNum(long beginRecordNum)
	{
		this.beginRecordNum = beginRecordNum;
	}

	public long getEndRecordNum()
	{
		return endRecordNum;
	}

	public void setEndRecordNum(long endRecordNum)
	{
		this.endRecordNum = endRecordNum;
	}

	public Map<String, Object> getParams()
	{
		return params;
	}

	public void setParams(Map<String, Object> params)
	{
		this.params = params;
	}

	public String getPageCententHTML()
	{
		return pageCententHTML;
	}

	public void setPageCententHTML(String pageCententHTML)
	{
		this.pageCententHTML = pageCententHTML;
	}

	public String getUrl()
	{
		return url;
	}

	public void setUrl(String url)
	{
		this.url = url;
	}
	
}
